﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section header{

}

<body>
    <input type="hidden" id="isReload" value="0">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <button class="layui-btn" data-type="Delete">清除日志</button>
                    </div>
                    <div class="layui-card-body ">
                        <table class="layui-table" lay-data="{id: 'taskTable'}" lay-filter="demo">
                            <thead>
                                <tr>
                                    <th lay-data="{field:'createTime', width: 180 }">时间</th>
                                    <th lay-data="{field:'content', minWidth:300}">日志内容</th>
                                    <th lay-data="{field:'exception', minWidth:300}">日志异常</th>
                                </tr>
                            </thead>
                        </table>
                        <div class="layui-form-item" style="text-align: center;">
                            <button type="button" class="layui-btn layui-btn-primary" function="close">关闭</button>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</body>

<script>
    layui.use(['table', 'laypage'], function () {
        var table = layui.table;

        $("[function='close']").click(function () {
            common.closeOpen();
        });
        var taskId = common.getUrlParam("taskId");

        table.reload("taskTable", {
            height: "full-180",
            // width: 'full-20',
            loading: true,
            page: true,
            limit: 30,
            request: {
                pageName: "pageIndex",
                limitName: "pageSize"
            },
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.statusCode, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.totalCount, //解析数据长度
                    "data": res.data.pageData //解析数据列表
                };
            }
        });

        function tableReload() {
            table.reload("taskTable", {
                url: "/Schedule/GetLogPaging",
                where: {
                    taskId: taskId
                }
            });
        }

        tableReload();

        var active = {
            Delete: function () {
                $("#isReload").val("0")
                common.open("删除日志", "500px", "500px", common.versionUrl("/Schedule/DeleteLog?taskId=" + taskId), 0, function () {
                    if ($("#isReload").val() == "1") {
                        tableReload();
                    }
                });
            }
        };

        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>